export function toggleAll (state) {
  if (state.selectAll) {
    let result = []
    state.publish.every(function (pub) {
      if (pub.status === 0) {
        result.push(pub.id)
      }
      return pub.id
    })
    state.selected = result
  } else {
    state.selected = []
  }
}

export function clearAll (state) {
  state.grayProcess = 0
  state.rollProcess = 0
  state.rollPub = []
  state.waitPub = []
  state.grayPub = []
  state.grayDone = []
  state.rollDone = []
  clearInterval(state.rollInterval)
  clearInterval(state.grayInterval)
}

export function closeRollDialog (state) {
  state.rollPubDialog = false
}

export function closeGrayDialog (state) {
  state.grayPubDialog = false
}

export function loadListSuccess (state, payload) {
  state.waitPub = payload.rows
}

export function loadRollSuccess (state, payload) {
  state.rollDone = payload.rows
  state.rollProcess = payload.progress
}

export function loadGraySuccess (state, payload) {
  state.grayDone = payload.rows
  state.grayProcess = payload.progress
}

export function doRollPublishSuccess (state, payload) {
  alert(payload.data)
  state.rollPub = []
  state.rollPubDialog = false
}

export function doGrayPublishSuccess (state, payload) {
  alert(payload.data)
  state.grayPub = []
  state.grayPubDialog = false
}
